<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('投资项目') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input v-model="queryParams.dealName" :placeholder="$t('项目名称')" clearable />
      </el-form-item>
      <el-form-item :label="$t('投资基金')" prop="fundName">
        <el-input v-model="queryParams.fundName" :placeholder="$t('投资基金')" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="investDealInfos" border>
      <el-table-column :label="$t('项目名称')" prop="dealName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('投资基金')" prop="fundName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('币种')" prop="currency" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ getDictVaule('currencys',scope.row.currency) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('已投资金额') + $t('金额单位')" prop="amountInvested" align="center" show-overflow-tooltip width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.amountInvested, 'w') }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('最新持股比例(%)')" prop="latestShareholdingRatio" align="center" show-overflow-tooltip width="130">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.latestShareholdingRatio) }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('首次付款时间')" prop="firstPaymentTime" align="center" show-overflow-tooltip width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstPaymentTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('已收回金额') + $t('金额单位')" prop="recoveredAmount" align="center" show-overflow-tooltip width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.recoveredAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目IRR')" prop="dealIrr" align="center" show-overflow-tooltip width="130" />
      <el-table-column :label="$t('上市情况')" prop="listing" align="center" show-overflow-tooltip width="130">
        <template slot-scope="scope">
          <span>{{ getDictVaule('listings',scope.row.listing) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { findInvestDealInfo } from '@/api/fund/lpBase/lpBase'

export default {
  data() {
    return {
      total: 0,
      dict: {
        currencys: [],
        listings: []
      },
      queryParams: {
        lpId: this.$route.query.lpId,
        fundName: undefined,
        dealName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      loading: false,
      investDealInfos: []
    }
  },
  mounted() {
    this.initDict()
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      findInvestDealInfo(this.queryParams).then(response => {
        this.investDealInfos = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterange = []
      this.resetForm('queryForm')
      this.queryHandle()
    },
    initDict() {
      // 币种
      this.getDicts('currency').then(response => {
        this.dict.currencys = response.data
      })
      this.getDicts('bf_group_listed_situation').then(response => {
        this.dict.listings = response.data
      })
    },
    getDictVaule(listName, key) {
      const list = this.dict[listName]
      for (let i = 0; i < list.length; i++) {
        const dict = list[i]
        if (dict.dictValue === key) {
          return dict.dictLabel
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
